package com.hualan.sfzy.service.counselor.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.counselor.Counselor;
import com.hualan.sfzy.entity.counselor.CounselorTalent;
import com.hualan.sfzy.mapper.counselor.CounselorTalentMapper;
import com.hualan.sfzy.service.counselor.CounselorTalentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("CounselorTalentService")
public class CounselorTalentServiceImpl implements CounselorTalentService {
    @Autowired
    private CounselorTalentMapper counselorTalentMapper;

    @Override
    public int add(CounselorTalent entity) {
        return counselorTalentMapper.insert(entity);
    }

    @Override
    public int edit(CounselorTalent entity) {
        return counselorTalentMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return counselorTalentMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return counselorTalentMapper.deleteBatch(ids);
    }

    @Override
    public List<CounselorTalent> find() {
        return counselorTalentMapper.select(null);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, CounselorTalent entity) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        //当前页数据
        List<CounselorTalent> list = counselorTalentMapper.select(entity);
        PageInfo<CounselorTalent> pageInfo = new PageInfo<>(list);
        Map<String,Object> map = new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public CounselorTalent findById(Integer id) {
        return counselorTalentMapper.selectById(id);
    }

    @Override
    public int addBatch(List<CounselorTalent> list) {
        return counselorTalentMapper.insertBatch(list);
    }

    @Override
    public int removeByCounselorId(Integer counselorId) {
        return counselorTalentMapper.deleteByCounselorId(counselorId);
    }
}
